package aspectos.contador;

import java.util.HashMap;

public aspect ContadorLlamadasAspect pertarget(execution((@Monitored *).new(..))) {
	
	private HashMap<String, Integer> cants = new HashMap<String, Integer>();
	
	pointcut executing(Object target) : 
		execution(@Monitored * dominio.contador.*.*(..)) && target(target);
	
	after(Object target) : executing(target) {
		String fieldName = thisJoinPoint.getSignature().getName();
		
		cants.put(fieldName, cantLlamadas(fieldName) + 1);
	}
	
	//**********************************************************************/
	
	public Integer cantLlamadas(String method) {
		if(cants.get(method) == null) {
			return 0;
		} else {
			return cants.get(method);
		}
	}
	
}
